#!/bin/sh


if [ "$#" -eq 1 ] || [ "$#" -eq 2 ]
then
  echo "Starting db restore ..."
else
  echo "Usage: `basename $0` {backupID} [-no-att]"
  exit $E_BADARGS
fi


echo unarchiving ${WORK_DIR}/$1.db-backup.tar
cd ${BACKUP_DIR}

if [ "$#" -eq 1 ]; 
then 
	tar xvf ${WORK_DIR}/$1.db-backup.tar
else
	tar xvf ${WORK_DIR}/$1.db-backup.tar --wildcards *.db-backup
fi

export MYSQL_='mysql --user=mzm --password=mzm'
echo recreating db tables
$MYSQL_ -e "DROP DATABASE IF EXISTS mzm;"
$MYSQL_ -e "CREATE DATABASE mzm DEFAULT CHARSET utf8;"

echo restoring db content
mysql --user=mzm --password=mzm mzm < mzm-$1.db-backup